using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;

namespace DOMercury.Managers
{
    class SkinManager
    {
        private static ManagedWinapi.Hotkey hk;
        private static SkinSet skin;
        public static bool ReadSkin(string filename)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            if (File.Exists(filename))
            {
                FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                while (!sr.EndOfStream)
                {
                    string cl = sr.ReadLine();
                    if ((!cl.StartsWith("-")) && (cl != ""))
                    {
                        try
                        {
                            string[] valpair = cl.Split(':');
                        dic.Add(valpair[0].Trim(), valpair[1].Trim());
                        }
                        catch
                        {

                        }

                    }
                }
                skin = new SkinSet();
                skin.Name = Path.GetFileNameWithoutExtension(filename);
                string temp;
                #region Conversions

                dic.TryGetValue("ActionIconVisible", out temp);
                try
                {
                    skin.ActionIconVisible = Convert.ToBoolean(temp);
                }
                catch (Exception ex)
                {

                }

                dic.TryGetValue("ItemIconVisible", out temp);
                try
                {
                    skin.ItemIconVisible = Convert.ToBoolean(temp);
                }
                catch (Exception ex)
                {

                }
                
                dic.TryGetValue("ActionsBoxXLoc", out temp);
               
                try{
                skin.ActionsBoxXLoc = Convert.ToInt32(temp);
                }
                catch(Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ActionsBoxYLoc", out temp);

                try
                {
                    skin.ActionsBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ActionsBoxWidth", out temp);

                try
                {
                    skin.ActionsBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsBoxWidth", out temp);

                try
                {
                    skin.ParamsBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ActionsDescriptionFont", out temp);
               
                try
                {
                skin.ActionsDescriptionFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsDescriptionsHeight", out temp);
                
                try
                {
                    skin.ActionsDescriptionsHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsDescriptionsWidth", out temp);
                
                try
                {
                    skin.ActionsDescriptionsWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsDescriptionsXLoc", out temp);
                
                try
                {
                    skin.ActionsDescriptionsXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsDescriptionsYLoc", out temp);
                
                try
                {
                    skin.ActionsDescriptionsYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsLabelFont", out temp);
                
                try
                {
                    skin.ActionsLabelFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsLabelXLoc", out temp);
                
                try
                {
                    skin.ActionsLabelXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActionsLabelYLoc", out temp);
                
                try
                {
                    skin.ActionsLabelYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ActivePanelColor", out temp);
                
                try
                {
                    
                    skin.ActivePanelColor = System.Drawing.Color.FromName(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BackPanelHeight", out temp);
                
                try
                {
                    skin.BackPanelHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BackPanelImage", out temp);
                
                try
                {
                    skin.BackPanelImage = temp;
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BackPanelWidth", out temp);
                
                try
                {
                    skin.BackPanelWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BackPanelXLoc", out temp);
                
                try
                {
                    skin.BackPanelXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BackPanelYLoc", out temp);
                
                try
                {
                    skin.BackPanelYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("CurrentItemFont", out temp);
                
                try
                {
                    skin.CurrentItemFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("CurrentItemWidth", out temp);
                
                try
                {
                    skin.CurrentItemWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("CurrentItemXLoc", out temp);
                
                try
                {
                    skin.CurrentItemXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("CurrentItemYLoc", out temp);
                
                try
                {
                    skin.CurrentItemYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("DescriptionsVisible", out temp);
                
                try
                {
                    skin.DescriptionsVisible = Convert.ToBoolean(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("InactivePanelColor", out temp);
                    
                    
                try
                {
                    skin.InactivePanelColor = System.Drawing.Color.FromName(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BoxBackBrush", out temp);
                
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);
                    skin.ItemsBoxBackBrush = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("BoxFont", out temp);
               
                try
                {
                    skin.ItemsBoxFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsBoxHeight", out temp);
                
                try
                {
                    skin.ItemsBoxHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BoxSelectedBackBrush", out temp);
                
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);
                    skin.ItemsBoxSelectedBackBrush = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BoxSelectedTextBrush", out temp);
                
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);

                    skin.ItemsBoxSelectedTextBrush = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("BoxTextBrush", out temp);
                
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);

                    skin.ItemsBoxTextBrush = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsBoxWidth", out temp);
                
                try
                {
                    skin.ItemsBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsBoxXLoc", out temp);
                
                try
                {
                    skin.ItemsBoxXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsBoxYLoc", out temp);
                
                try
                {
                    skin.ItemsBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsLabelFont", out temp);
                
                try
                {
                    skin.ItemsLabelFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsLabelXLoc", out temp);
                
                try
                {
                    skin.ItemsLabelXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsLabelYLoc", out temp);
                
                try
                {
                    skin.ItemsLabelYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsTextBoxFont", out temp);
                
                try
                {
                    skin.ItemsTextBoxFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ItemsTextBoxWidth", out temp);
                
                try
                {
                    skin.ItemsTextBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsTextBoxXLoc", out temp);
                
                try
                {
                    skin.ItemsTextBoxXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ItemsTextBoxYLoc", out temp);
                
                try
                {
                    skin.ItemsTextBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemsTextBoxBackColor", out temp);

                try
                {
                    skin.ItemsTextBoxBackColor = System.Drawing.Color.FromName(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemsTextBoxFontColor", out temp);

                try
                {
                    skin.ItemsTextBoxFontColor = System.Drawing.Color.FromName(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("LabelsVisible", out temp);
                
                try
                {
                    skin.LabelsVisible = Convert.ToBoolean(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParamsBoxXLoc", out temp);
                
                try
                {
                    skin.ParamsBoxXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParamsBoxYLoc", out temp);
                
                try
                {
                    skin.ParamsBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParamsDescriptionFont", out temp);
                
                try
                {
                    skin.ParamsDescriptionFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParamsDescriptionsHeight", out temp);
                
                try
                {
                    skin.ParamsDescriptionsHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParamsDescriptionsWidth", out temp);
                
                try
                {
                    skin.ParamsDescriptionsWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParamsDescriptionsXLoc", out temp);
                
                try
                {
                    skin.ParamsDescriptionsXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParamsDescriptionsYLoc", out temp);
                
                try
                {
                    skin.ParamsDescriptionsYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParamsLabelFont", out temp);
                
                try
                {
                    skin.ParamsLabelFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParamsLabelXLoc", out temp);
               
                try
                {
                    skin.ParamsLabelXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParamsLabelYLoc", out temp);
                
                try
                {
                    skin.ParamsLabelYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParentItemFont", out temp);
                
                try
                {
                    skin.ParentItemFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("ParentItemWidth", out temp);
               
                try
                {
                    skin.ParentItemWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParentItemXLoc", out temp);
                
                try
                {
                    skin.ParentItemXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("ParentItemYLoc", out temp);
                
                try
                {
                    skin.ParentItemYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("SelectedItemsBoxBackColor", out temp);
               
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);

                    skin.SelectedItemsBoxBackColor = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("SelectedItemsBoxFont", out temp);
                
                try
                {
                    skin.SelectedItemsBoxFont = FontParser.ParseFont(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("SelectedItemsBoxFontColor", out temp);
               
                try
                {
                    System.Drawing.Color tmp = System.Drawing.Color.FromName(temp);

                    skin.SelectedItemsBoxFontColor = new SolidBrush(tmp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("SelectedItemsBoxHeight", out temp);
                
                try
                {
                    skin.SelectedItemsBoxHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("SelectedItemsBoxWidth", out temp);
               
                try
                {
                    skin.SelectedItemsBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
                
                dic.TryGetValue("SelectedItemsBoxXLoc", out temp);
               
                try
                {
                    skin.SelectedItemsBoxXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }
               
                dic.TryGetValue("SelectedItemsBoxYLoc", out temp);
                
                try
                {
                    skin.SelectedItemsBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemIconXLoc", out temp);

                try
                {
                    skin.ItemIconXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemIconYLoc", out temp);

                try
                {
                    skin.ItemIconYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemIconSize", out temp);

                try
                {
                    skin.ItemIconSize = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ActionIconXLoc", out temp);

                try
                {
                    skin.ActionIconXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ActionIconYLoc", out temp);

                try
                {
                    skin.ActionIconYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ActionIconSize", out temp);

                try
                {
                    skin.ActionIconSize = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsItemsBoxWidth", out temp);

                try
                {
                    skin.ParamsItemsBoxWidth = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsItemsBoxHeight", out temp);

                try
                {
                    skin.ParamsItemsBoxHeight = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsItemsBoxXLoc", out temp);

                try
                {
                    skin.ParamsItemsBoxXLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsItemsBoxYLoc", out temp);

                try
                {
                    skin.ParamsItemsBoxYLoc = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ParamsBoxBackgroundAlpha", out temp);

                try
                {
                    skin.ParamsBoxBackgroundAlpha = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                dic.TryGetValue("ItemsTextBoxBackgroundAlpha", out temp);

                try
                {
                    skin.ItemsTextBoxBackgroundAlpha = Convert.ToInt32(temp);
                }
                catch (Exception ex)
                {
                    //System.Windows.Forms.MessageBox.Show("Error Reading Skin element: " + ex.Message);
                }

                #endregion


                sr.Close();
                fs.Close();
            }
            
            return true;
        }

        public static SkinSet CurrentSkin
        {
            get
            {
                if (skin != null)
                {
                    return skin;
                }
                else
                {
                    return defaultSkin;
                }
            }
        }

        private static SkinSet defaultSkin
        {
            get
            {
                return new SkinSet();
            }
        }
            
    }

    public class SkinSet
    {
        private int bpHeight, bpWidth, bpX, bpY;
        private string bpImage;
        private bool shVisible;
        private Font lbliFont;
        private int lbliX, lbliY;
        private int cbiX, cbiY, cbiWidth;
        private Font cbiFont;
        private bool lblsVisible;
        private int lbiX, lbiY, lbiHeight, lbiWidth;
        private Font lbiFont;
        private Brush lbiBackBrush;
        private Brush lbiSelectedBackBrush;
        private Brush lbiTextBrush;
        private Brush lbiSelectedTextBrush;
        private int lboX, lboY, lboHeight, lboWidth;
        private Font lboFont;
        private Brush lboBackBrush, lboTextBrush;
        private int lblaX, lblaY;
        private Font lblaFont;
        private int lblpX, lblpY;
        private Font lblpFont;
        private int adscX, adscY, adscHeight, adscWidth;
        private Font adscFont;
        private bool dscsVisible;
        private int pdscX, pdscY, pdscHeight, pdscWidth;
        private Font pdscFont;
        private int cbaX, cbaY, cbaWidth;
        private Font cbaFont;
        private int cbpX, cbpY, cbpWidth, lbpWidth, lbpHeight, lbpX, lbpY;
        private Font cbpFont;
        private int pX, pY, iX, iY;
        private Color ap, ip;
        private int ciWidth, ciHeight, piWidth, piHeight;
        private Font piFont, ciFont;
        private string name;
        private Color cbiBackColor, cbiFontColor;

        private bool iiconvis = false;
        private bool aiconvis = false;
        private int aiX, aiY, aiS, iiX, iiY, iiS;
        private int itbAplha, ptbAlpha;

        public SkinSet()
        {
            //Set defaults here
            //BackPanel
            bpX = 12;
            bpY = 12;
            bpWidth = 742;
            bpHeight = 193;
            bpImage = "back3.png";
            //Lbls
            lblsVisible = true;
            //lblItems
            lbliX = 8;
            lbliY = 7;
            lbliFont = FontParser.ParseFont("Arial, 11.25pt");
            //lblActions
            lblaX = 253;
            lblaY = 7;
            lblaFont = FontParser.ParseFont("Arial, 11.25pt");
            //lblParams
            lblpX = 505;
            lblpY = 7;
            lblpFont = FontParser.ParseFont("Arial, 11.25pt");
            //cbItems
            cbiX = 12;
            cbiY = 34;
            cbiWidth = 221;
            cbiFont = FontParser.ParseFont("Arial, 11.25pt");
            cbiBackColor = Color.Black;
            cbiFontColor = Color.Yellow;
            //cbAction
            cbaX = 257;
            cbaY = 150;
            cbaWidth = 231;
            cbaFont = FontParser.ParseFont("Arial, 11.25pt");
            //cbParams
            cbpX = 505;
            cbpY = 150;
            cbpWidth = 231;
            cbpFont = FontParser.ParseFont("Arial, 11.25pt");
            //Descriptions
            dscsVisible = true;
            //ActionDescriptions
            adscX = 253;
            adscY = 31;
            adscWidth = 231;
            adscHeight = 116;
            adscFont = FontParser.ParseFont("Arial, 11.25pt");
            //ParamsDescriptions
            pdscX = 505;
            pdscY = 31;
            pdscWidth = 231;
            pdscHeight = 116;
            pdscFont = FontParser.ParseFont("Arial, 11.25pt");
            //lbObjects 12 34 221 112
            lboX = 12;
            lboY = 34;
            lboWidth = 221;
            lboHeight = 112;
            lboFont = FontParser.ParseFont("Arial, 11.25pt");
            lboTextBrush = Brushes.Black;
            lboBackBrush = Brushes.White;
            //lbItems 15 203 233 334
            lbiX = 15;
            lbiY = 203;
            lbiWidth = 233;
            lbiHeight = 334;
            lbiBackBrush = Brushes.White;
            lbiSelectedBackBrush = Brushes.Blue;
            lbiTextBrush = Brushes.Black;
            lbiSelectedTextBrush = Brushes.White;
            lbiFont = FontParser.ParseFont("Arial, 8.25pt");
            //ParentItem
            pX = 12;
            pY = 59;
            piWidth = 235;
            piHeight = 62;
            piFont = FontParser.ParseFont("Arial, 8.25pt");
            //CurrentItem
            iX = 12;
            iY = 123;
            ciWidth = 235;
            ciHeight = 67;
            ciFont = FontParser.ParseFont("Arial, 8.25pt");
            //ActivePanelBrush
            ap = Color.Green;
            ip = Color.Black;
            //InactivePanelBrush

            //Item and Action Icons
            iiX = 0;
            iiY = 0;
            iiS = 32;
            aiX = 0;
            aiY = 0;
            aiS = 32;
            itbAplha = 0;
            ptbAlpha = 0;
        }
        #region Properties
        public bool ItemIconVisible
        {
            get
            {
                return iiconvis;
            }
            set
            {
                iiconvis = value;
            }
        }

        public int ItemIconXLoc
        {
            get
            {
                return iiX;
            }
            set
            {
                iiX = value;
            }
        }

        public int ItemIconYLoc
        {
            get
            {
                return iiY;
            }
            set
            {
                iiY = value;
            }
        }

        public int ItemIconSize
        {
            get
            {
                return iiS;
            }
            set
            {
                iiS = value;
            }
        }

        public int ActionIconXLoc
        {
            get
            {
                return aiX;
            }
            set
            {
                aiX = value;
            }
        }

        public int ActionIconYLoc
        {
            get
            {
                return aiY;
            }
            set
            {
                aiY = value;
            }
        }

        public int ActionIconSize
        {
            get
            {
                return aiS;
            }
            set
            {
                aiS = value;
            }
        }

        public bool ActionIconVisible
        {
            get
            {
                return aiconvis;
            }
            set
            {
                aiconvis = value;
            }
        }

        public int ParentItemWidth
        {
            get
            {
                return ciWidth;
            }
            set
            {
                ciWidth = value;
            }
        }

        public int CurrentItemWidth
        {
            get
            {
                return piWidth;
            }
            set
            {
                piWidth = value;
            }
        }

        public Font ParentItemFont
        {
            get
            {
                return piFont;
            }
            set
            {
                piFont = value;
            }
        }

        public Font CurrentItemFont
        {
            get
            {
                return ciFont;
            }
            set
            {
                ciFont = value;
            }
        }

        public int BackPanelHeight
        {
            get
            {
                return bpHeight;
            }
            set
            {
                bpHeight = value;
            }
        }

        public int BackPanelWidth
        {
            get
            {
                return bpWidth;
            }
            set
            {
                bpWidth = value;
            }
        }

        public int BackPanelXLoc
        {
            get
            {
                return bpX;
            }
            set
            {
                bpX = value;
            }
        }

        public int BackPanelYLoc
        {
            get
            {
                return bpY;
            }
            set
            {
                bpY = value;
            }
        }

        public string BackPanelImage
        {
            get
            {
                return bpImage;
            }
            set
            {
                bpImage = value;
            }
        }

        public bool ShadowVisible
        {

            get
            {
                return shVisible;
            }
            set
            {
                shVisible = true;
            }
        }

        public Font ItemsLabelFont
        {
            get
            {
                return lbliFont;
            }
            set
            {
                lbliFont = value;
            }
        }

        public int ItemsLabelXLoc
        {
            get
            {
                return lbliX;

            }
            set
            {
                lbliX = value;
            }
        }

        public int ItemsLabelYLoc
        {
            get
            {
                return lbliY;

            }
            set
            {
                lbliY = value;
            }
        }

        public Font ActionsLabelFont
        {
            get
            {
                return lblaFont;
            }
            set
            {
                lblaFont = value;
            }
        }

        public int ActionsLabelXLoc
        {
            get
            {
                return lblaX;

            }
            set
            {
                lblaX = value;
            }
        }

        public int ActionsLabelYLoc
        {
            get
            {
                return lblaY;

            }
            set
            {
                lblaY = value;
            }
        }

        public Font ParamsLabelFont
        {
            get
            {
                return lblpFont;
            }
            set
            {
                lblpFont = value;
            }
        }

        public int ParamsLabelXLoc
        {
            get
            {
                return lblpX;

            }
            set
            {
                lblpX = value;
            }
        }

        public int ParamsLabelYLoc
        {
            get
            {
                return lblpY;

            }
            set
            {
                lblpY = value;
            }
        }

        public Font ItemsBoxFont
        {
            get
            {
                return lbiFont;
            }
            set
            {
                lbiFont = value;
            }
        }

        public int ItemsBoxXLoc
        {
            get
            {
                return lbiX;

            }
            set
            {
                lbiX = value;
            }
        }

        public int ItemsBoxYLoc
        {
            get
            {
                return lbiY;

            }
            set
            {
                lbiY = value;
            }
        }

        public int ItemsBoxHeight
        {
            get
            {
                return lbiHeight;
            }
            set
            {
                lbiHeight = value;
            }
        }

        public int ItemsBoxWidth
        {
            get
            {
                return lbiWidth;
            }
            set
            {
                lbiWidth = value;
            }
        }

        public Brush ItemsBoxBackBrush
        {
            get
            {
                return lbiBackBrush;
            }
            set
            {
                lbiBackBrush = value;
            }
        }

        public Brush ItemsBoxSelectedBackBrush
        {
            get
            {
                return lbiSelectedBackBrush;
            }
            set
            {
                lbiSelectedBackBrush = value;
            }
        }

        public Brush ItemsBoxTextBrush
        {
            get
            {
                return lbiTextBrush;
            }
            set
            {
                lbiTextBrush = value;
            }
        }

        public Brush ItemsBoxSelectedTextBrush
        {
            get
            {
                return lbiSelectedTextBrush;
            }
            set
            {
                lbiSelectedTextBrush = value;
            }
        }

        public int SelectedItemsBoxXLoc
        {
            get
            {
                return lboX;
            }
            set
            {
                lboX = value;
            }
        }

        public int SelectedItemsBoxYLoc
        {
            get
            {
                return lboY;
            }
            set
            {
                lboY = value;
            }
        }

        public int SelectedItemsBoxHeight
        {
            get
            {
                return lboHeight;
            }
            set
            {
                lboHeight = value;
            }
        }

        public int SelectedItemsBoxWidth
        {
            get
            {
                return lboWidth;
            }
            set
            {
                lboWidth = value;
            }
        }

        public Font SelectedItemsBoxFont
        {
            get
            {
                return lboFont;
            }
            set
            {
                lboFont = value;
            }
        }

        public Font ActionsBoxFont
        {
            get
            {
                return cbaFont;
            }
            set
            {
                cbaFont = value;
            }
        }

        public int ActionsBoxXLoc
        {
            get
            {
                return cbaX;
            }
            set
            {
                cbaX = value;
            }
        }

        public int ActionsBoxYLoc
        {
            get
            {
                return cbaY;
            }
            set
            {
                cbaY = value;
            }
        }

        public Font ParamsBoxFont
        {
            get
            {
                return cbpFont;
            }
            set
            {
                cbpFont = value;
            }
        }

        public int ParamsBoxXLoc
        {
            get
            {
                return cbpX;
            }
            set
            {
                cbpX = value;
            }
        }

        public int ParamsBoxYLoc
        {
            get
            {
                return cbpY;
            }
            set
            {
                cbpY = value;
            }
        }

        public int ParamsBoxBackgroundAlpha
        {
            get
            {
                return ptbAlpha;
            }
            set
            {
                ptbAlpha = value;
            }
        }

        public int ItemsTextBoxBackgroundAlpha
        {
            get
            {
                return itbAplha;
            }
            set
            {
                itbAplha = value;
            }
        }

        public int ItemsTextBoxXLoc
        {
            get
            {
                return cbiX;
            }
            set
            {
                cbiX = value;
            }
        }

        public int ItemsTextBoxYLoc
        {
            get
            {
                return cbiY;
            }
            set
            {
                cbiY = value;
            }
        }

        public int ItemsTextBoxWidth
        {
            get
            {
                return cbiWidth;
            }
            set
            {
                cbiWidth = value;
            }
        }

        public bool LabelsVisible
        {
            get
            {
                return lblsVisible;
            }
            set
            {
                lblsVisible = value;
            }
        }

        public Color ActivePanelColor
        {
            get
            {
                return ap;
            }
            set
            {
                ap = value;
            }
        }

        public Color InactivePanelColor
        {
            get
            {
                return ip;
            }
            set
            {
                ip = value;
            }
        }

        public bool DescriptionsVisible
        {
            get
            {
                return dscsVisible;
            }
            set
            {
                dscsVisible = value;
            }
        }

        public int ParentItemXLoc
        {
            get
            {
                return pX;
            }
            set
            {
                pX = value;
            }
        }

        public int ParentItemYLoc
        {
            get
            {
                return pY;
            }
            set
            {
                pY = value;
            }
        }

        public int CurrentItemXLoc
        {
            get
            {
                return iX;
            }
            set
            {
                iX = value;
            }
        }

        public int CurrentItemYLoc
        {
            get
            {
                return iY;
            }
            set
            {
                iY = value;
            }
        }

        public int ActionsDescriptionsXLoc
        {
            get
            {
                return adscX;
            }
            set
            {
                adscX = value;
            }
        }

        public int ActionsDescriptionsYLoc
        {
            get
            {
                return adscY;
            }
            set
            {
                adscY = value;
            }
        }

        public int ActionsDescriptionsWidth
        {
            get
            {
                return adscWidth;
            }
            set
            {
                adscWidth = value;
            }
        }

        public int ActionsDescriptionsHeight
        {
            get
            {
                return adscHeight;
            }
            set
            {
                adscHeight = value;
            }
        }

        public Font ActionsDescriptionFont
        {
            get
            {
                return adscFont;
            }
            set
            {
                adscFont = value;
            }
        }

        public int ParamsDescriptionsXLoc
        {
            get
            {
                return pdscX;
            }
            set
            {
                pdscX = value;
            }
        }

        public int ParamsDescriptionsYLoc
        {
            get
            {
                return pdscY;
            }
            set
            {
                pdscY = value;
            }
        }

        public int ParamsDescriptionsWidth
        {
            get
            {
                return pdscWidth;
            }
            set
            {
                pdscWidth = value;
            }
        }

        public int ParamsDescriptionsHeight
        {
            get
            {
                return pdscHeight;
            }
            set
            {
                pdscHeight = value;
            }
        }

        public Font ParamsDescriptionFont
        {
            get
            {
                return pdscFont;
            }
            set
            {
                pdscFont = value;
            }
        }

        public Font ItemsTextBoxFont
        {
            get
            {
                return cbiFont;
            }
            set
            {
                cbiFont = value;
            }
        }

        public Brush SelectedItemsBoxBackColor
        {
            get
            {
                return lboBackBrush;
            }
            set
            {
                lboBackBrush = value;
            }
        }

        public Brush SelectedItemsBoxFontColor
        {
            get
            {
                return lboTextBrush;
            }
            set
            {
                lboTextBrush = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public int ActionsBoxWidth
        {
            get
            {
                return cbaWidth;
            }
            set
            {
                cbaWidth = value;
            }
        }

        public int ParamsBoxWidth
        {
            get
            {
                return cbpWidth;
            }
            set
            {
                cbpWidth = value;
            }
        }

        public Color ItemsTextBoxBackColor
        {
            get
            {
                return cbiBackColor;
            }
            set
            {
                cbiBackColor = value;
            }
        }

        public Color ItemsTextBoxFontColor
        {
            get
            {
                return cbiFontColor;
            }
            set
            {
                cbiFontColor = value;
            }
        }

        public int ParamsItemsBoxXLoc
        {
            get
            {
                return lbpX;

            }
            set
            {
                lbpX = value;
            }
        }

        public int ParamsItemsBoxYLoc
        {
            get
            {
                return lbpY;

            }
            set
            {
                lbpY = value;
            }
        }

        public int ParamsItemsBoxHeight
        {
            get
            {
                return lbpHeight;
            }
            set
            {
                lbpHeight = value;
            }
        }

        public int ParamsItemsBoxWidth
        {
            get
            {
                return lbpWidth;
            }
            set
            {
                lbpWidth = value;
            }
        }

        #endregion
    }

    class FontParser
    {
        public static Font ParseFont(string fontstring)
        {
            try
            {
                string[] splits = fontstring.Split(',');
                double pt = Convert.ToDouble(splits[1].Replace("pt", ""));
                return new Font(splits[0], (float)pt);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("A font is formatted incorrectly in the skin file: " + fontstring);
                return new Font("Arial", 11.25F);
            }
        }
    }

    class EnumHelper
    {
        public static T StringToEnum<T>(string str)
        {
            if (str.Trim().Length == 0)
            {
                str = "";
            }
           
            try
            {
                return (T)System.Enum.Parse(typeof(T), str);
            }
            catch
            {
                return default(T);
            }
        }
        public static string EnumToString<T>(T e)
        {
            string str = e.ToString();
           
            return str;
        }
    } 
}
